package com.xzp.blog.service.impl;

import com.xzp.blog.entity.Tag;
import com.xzp.blog.entity.vo.TagView;
import com.xzp.blog.mapper.TagMapper;
import com.xzp.blog.service.BaseViewTransableService;
import com.xzp.blog.service.ITagService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * 文章标签相关业务实现类
 */
@Service
public class TagServiceImpl extends BaseViewTransableService<Tag,TagView> implements ITagService {

    @Autowired
    private TagMapper tagMapper;

    @Override
    public List<TagView> getAllTagView() {
        return tagMapper.selectAllTagView();  //这里是从sql语句组合成TagView对象
    }

    @Override
    protected List<TagView> transEntityToView(List<Tag> entityList) {
        List<TagView> tagViewList = new ArrayList<>();
        for (Tag tag : entityList) {
            tagViewList.add(new TagView(tag));
        }
        return tagViewList;
    }
}
